#include <iostream>
#include "string.h"

using namespace std;
int foo(const char *substr) {
    int n = strlen (substr);
    int shift[n];
    int i;
    shift[0] = 0;
    for(i = 1; i < n; i++) {
        if(substr[i] == substr[shift[i-1]]) {
        shift[i] = shift[i - 1] + 1;
        }
        else {
        shift[i] = 0;
        }
    }

    cout<<endl<<endl<<"FUMAFU ======"<<shift[i- 1];
    return shift[i-1];
}

int ololo(char* m, char* r){
    char* spam;

    const int stStr1 = strlen(m);
    const int stStr2 = strlen(r);
    int sdvig = 0;
    int i = 0;

    for(i+=sdvig;i<stStr1 - stStr2;)
    {
        for(int y = 0;y<stStr2;y++, i++)
        {
            if(m[i] == r[y])
            {
                spam[i] = m[i];
                cout<<endl<<endl<<endl<<"SKYRIM   "<<i<<endl<<endl;
                if(y==strlen(r))
                {
                    return i;
                }
            }
            else
            {
                cout<<m[i]<<' '<<r[y]<<' '<<i<<' ' <<y<<' ';
                cout<<"FAIL"<<endl;
                sdvig = foo(spam);
                y = sdvig-1;
                sdvig = strlen(spam) - sdvig;
                for(int u = 0;u<strlen(spam);u++)
                {
                    spam[u] = ' ';
                }
            }

        }
        break;
    }

}

int main() {
    cout<<"in";
    char* mas = "ababbabaababac";
    char* daba = "ababac";
    //cout<<endl<<" ITOG + "<<ololo(mas,daba);
    cout<<ololo(mas,daba);
    cout << endl<<endl<<endl<<endl<< "Hello world!" << endl<< endl<< endl;
    return 0;
}
